/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package systole.domain.clinicalInformation;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.Date;

import systole.domain.persons.Patient;
import systole.utils.Units;

/**
 * 
 * @author jmj
 */
public class ClinicalInformation implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 3021269678561974349L;
    private Integer id;
    private Date informationDate;
    private Integer years;
    private Integer height;
    private Float weight;
    private Float totalCholesterol;
    private Float hdl;
    private Float ldl;
    private Float triglycerides;
    private Float glucemic;
    private Patient patient;
    private Float systolicPressure;
    private Float diastolicPressure;
    private static final String NOT_FOUND = "No Disponible";

    /**
     * 
     */
    public ClinicalInformation() {
        super();
    }

    /**
     * @param patient
     */
    public ClinicalInformation(Patient patient) {
        this.patient = patient;
        this.informationDate = Calendar.getInstance().getTime();
    }

    /**
     * @return the id
     */
    public Integer getId() {
        return this.id;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * @return the height
     */
    public Integer getHeight() {
        return this.height;
    }

    /**
     * @param height
     *            the height to set
     */
    public void setHeight(Integer height) {
        this.height = height;
    }

    /**
     * @return the weight
     */
    public Float getWeight() {
        return this.weight;
    }

    /**
     * @param weight
     *            the weight to set
     */
    public void setWeight(Float weight) {
        this.weight = weight;
    } 

    /**
     * @return the totalCholesterol
     */
    public Float getTotalCholesterol() {
        return this.totalCholesterol;
    }

    /**
     * @param totalCholesterol
     *            the totalCholesterol to set
     */
    public void setTotalCholesterol(Float totalCholesterol) {
        this.totalCholesterol = totalCholesterol;
    }

    /**
     * @return hdl value
     */
    public Float getHdl() {
        return hdl;
    }

    /**
     * @param hdl the hdl to set
     */
    public void setHdl(Float hdl) {
        this.hdl = hdl;
    }

    /**
     * @return ldl value
     */
    public Float getLdl() {
        return ldl;
    }

    /**
     * @param ldl the ldl to set
     */
    public void setLdl(Float ldl) {
        this.ldl = ldl;
    }

    /**
     * @return the triglycerides
     */
    public Float getTriglycerides() {
        return this.triglycerides;
    }

    /**
     * @param triglycerides
     *            the triglycerides to set
     */
    public void setTriglycerides(Float triglycerides) {
        this.triglycerides = triglycerides;
    }

    /**
     * @return the glucemic
     */
    public Float getGlucemic() {
        return this.glucemic;
    }

    /**
     * @param glucemic
     *            the glucemic to set
     */
    public void setGlucemic(Float glucemic) {
        this.glucemic = glucemic;
    }

    /**
     * @return the systolicPressure
     */
    public Float getSystolicPressure() {
        return this.systolicPressure;
    }

    /**
     * @param showUnits if should be added unit
     * @return the systolicPressure as string
     */
    public String getSystolicPressureAsString(boolean showUnits) {
        if (this.systolicPressure == null) {
            return NOT_FOUND;
        }
        DecimalFormat format = new DecimalFormat("###0.0#");
        return format.format(this.systolicPressure) + ((showUnits) ? " " + Units.pressure : "");
    }

    /**
     * @param systolicPressure the systolicPressure to set
     */
    public void setSystolicPressure(Float systolicPressure) {
        this.systolicPressure = systolicPressure;
    }

    /**
     * @return the diastolicPressure
     */
    public Float getDiastolicPressure() {
        return this.diastolicPressure;
    }

    /**
     * @param showUnits if should be added unit
     * @return the diastolicPressure
     */
    public String getDiastolicPressureAsString(boolean showUnits) {
        if (this.diastolicPressure == null) {
            return NOT_FOUND;
        }
        DecimalFormat format = new DecimalFormat("###0.0#");
        return format.format(this.diastolicPressure) + ((showUnits) ? " " + Units.pressure : "");
    }

    /**
     * @param diastolicPressure the diastolicPressure to set
     */
    public void setDiastolicPressure(Float diastolicPressure) {
        this.diastolicPressure = diastolicPressure;
    }

    /**
     * @return the patient
     */
    public Patient getPatient() {
        return this.patient;
    }

    /**
     * @param patient
     *            the patient to set
     */
    public void setPatient(Patient patient) {
        this.patient = patient;
    }

    /**
     * @param showUnits if should be added unit
     * @return Height.
     */
    public String getHeightAsString(boolean showUnits) {
        return String.valueOf(this.height) + ((showUnits) ? " " + Units.Centimetres : "");
    }

    /**
     * @param showUnits if should be added unit
     * @return Weight
     */
    public String getWeightAsString(boolean showUnits) {
        DecimalFormat format = new DecimalFormat("###0.0#");
        return format.format(this.weight) + ((showUnits) ? " " + Units.kilograms : "");
    }

    /**
     * Method to get IMC
     *
     * @return patient IMC
     */
    public Float getIMC() {
        if ((this.weight == null) || (this.height == null)
                || (this.height.floatValue() <= 0)) {
            return new Float(0);
        }
        float mts = this.getHeight().floatValue() / 100;
        return new Float(this.getWeight()
                / ((mts * mts)));
    }

    /**
     * @return IMC as string
     */
    public String getIMCasString() {
        DecimalFormat format = new DecimalFormat("###0.0#");
        return format.format(this.getIMC());
    }

    /**
     * @return the informationDate
     */
    public Date getInformationDate() {
        return this.informationDate;
    }

    /**
     * @param informationDate the informationDate to set
     */
    public void setInformationDate(Date informationDate) {
        this.informationDate = informationDate;
    }

    /**
     * @param years the years to set
     */
    public void setYears(Integer years) {
        this.years = years;
    }

    /**
     * @return the years
     */
    public Integer getYears() {
        return years;
    }

    /**
     * @return the years as string
     */
    public String getYearsAsString() {
        return (this.years != null ? this.years.toString() : "");
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ClinicalInformation other = (ClinicalInformation) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.informationDate != other.informationDate && (this.informationDate == null || !this.informationDate.equals(other.informationDate))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 67 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 67 * hash + (this.informationDate != null ? this.informationDate.hashCode() : 0);
        return hash;
    }
}
